using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LANamp
{
    public partial class frmStart : Form
    {
        private bool autostart = false;

        public frmStart()
        {
            InitializeComponent();
        }

        private void tbName_Enter(object sender, EventArgs e)
        {
            tbName.SelectAll();
        }

        private void tbName_KeyUp(object sender, KeyEventArgs e)
        {
            btnStart.Enabled = (tbName.Text != "");
            if ((e.KeyCode == Keys.Enter) && (btnStart.Enabled)) btnStart_Click(sender, e);
        }

        private void frmStart_Load(object sender, EventArgs e)
        {
            labHostname.Text = System.Environment.MachineName.ToLower();
            tbName.Text = System.Environment.UserName + "'s server";
            string newName = "";
            foreach (string arg in System.Environment.GetCommandLineArgs())
            {
                if (arg.Substring(0, 6) == "/name=") newName = arg.Substring(6);
                if (arg == "/autostart") autostart = true;
            }
            if (newName != "") tbName.Text = newName;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmServerMain frmMain1 = new frmServerMain();
            frmMain1.Servername = tbName.Text;
            frmMain1.StartForm = this;
            frmMain1.Show();
        }

        private void frmStart_Shown(object sender, EventArgs e)
        {
            if (autostart) btnStart_Click(sender, e);

        }
    }
}